package com.aaa.ssm.service;

import com.aaa.ssm.dao.OperLogDao;
import com.aaa.ssm.entity.OperLog;
import com.aaa.ssm.service.OperLogService;
import com.aaa.ssm.util.Page;
import com.aaa.ssm.util.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ fileName:OperLogServiceImpl
 * @ description:
 * @ author:张圣福
 * @ createTime:2023/10/17 17:13
 * @ version:1.0.0
 */
@Service
public class OperLogServiceImpl implements OperLogService {
    @Resource
    private OperLogDao operLogDao;
    @Override
    public int add(OperLog operLog) {
        return operLogDao.add(operLog);
    }


    /*
     * 日志查询
     * */
    @Override
    public List<OperLog> queryAll(OperLog operLog) {
        return operLogDao.queryAll(operLog);
    }

    /*
     * 参数分页查询
     * */
    @Override
    public PageInfo selectAll(Page<OperLog> page) {
        PageHelper.startPage(page.getPageNo(), page.getPageSize());
        return new PageInfo(operLogDao.selectAll(page.getData()));
    }

    /*
     * 更新
     * */
    @Override
    public int Operupdate(OperLog operLog) {
        return operLogDao.Operupdate(operLog);
    }

    /*
     * 删除
     * */
    @Override
    public int Operdelete(Integer operId) {
        return operLogDao.Operdelete(operId);
    }

    /*
     * 批量删除
     * */
    @Override
    public Result OperdeleteBatchIds(List<OperLog> users) {
        List<Integer> collect = users.stream().map(item -> item.getOperId()).collect(Collectors.toList());
        int i  =  operLogDao.OperdeleteBatchIds(collect);
        if (i>0){
            return new Result(200,"批量删除成功",null);
        }else {
            return new Result(500,"批量删除失败",null);
        }
    }

    @Override
    public List<OperLog> countOper() {
        return operLogDao.countOper();
    }
}
